package com.qingmu.club.minaapi.controller.member;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qingmu.club.minaapi.plus.entity.Activity;

import com.qingmu.club.minaapi.plus.entity.ActivityCenter;
import com.qingmu.club.minaapi.plus.entity.Course;
import com.qingmu.club.minaapi.plus.service.ActivityCenterService;
import com.qingmu.club.minaapi.plus.service.ActivityService;
import com.qingmu.club.minaapi.utils.KeyValueDefine;
import com.qingmu.club.minaapi.utils.ResponseObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 活动主表 前端控制器
 * </p>
 *
 * @author duke
 * @since 2019-08-20
 */
@RestController
@CrossOrigin(origins = "*", methods = {RequestMethod.POST, RequestMethod.GET})
@Api(value = "活动相关(会员端小程序)", description = "活动相关(会员端小程序)")
@RequestMapping("/member/activity")
public class MemberActivityController {

    @Autowired
    ActivityService activityService;

    @Autowired
    ActivityCenterService activityCenterService;

    @RequestMapping(value = "/select", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "首页活动列表")
    public ResponseEntity select(

    ) {
        QueryWrapper<Activity> qw = new QueryWrapper<>();
        qw.eq(Activity.ACTIVITY_TYPE,0).eq(Activity.STATUS, KeyValueDefine.ONLINE_STATUS)
        .orderByAsc(Activity.SORT);//上架状态
        List<Activity> activityList  = activityService.list(qw);
        return ResponseObject.success(activityList);
    }

    //暂时未使用
//    @RequestMapping(value = "/selectShop", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
//    @ApiOperation(value = "门店活动")
//    public ResponseEntity selectShop(
//            @ApiParam(required = true, value = "门店id") @RequestParam(required = true) String shopId
//    ) {
//        QueryWrapper<Activity> qw = new QueryWrapper<>();
//        qw.eq(Activity.SHOP_ID,shopId).eq(Activity.ACTIVITY_TYPE,1)
//                .eq(Activity.STATUS, KeyValueDefine.ONLINE_STATUS);//上架状态
//        List<Activity> activityList  = activityService.list(qw);
//
//        return ResponseObject.success(activityList);
//    }

    @RequestMapping(value = "/getById", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    @ApiOperation(value = "查询活动详情")
    public ResponseEntity getById(
            @ApiParam(required = true, value = "活动id") @RequestParam(required = true) String activityId,
            @ApiParam(required = true, value = "活动类型") @RequestParam(required = true) Integer type
    ) {

        if (type == 1) {
            Activity activity = activityService.getById(activityId);
            if (activity == null) {
                return ResponseObject.error(601, "活动不存在");
            }
            return ResponseObject.success(activity);

        }

        ActivityCenter activity  = activityCenterService.getById(activityId);
        if(activity==null){
            return ResponseObject.error(601,"活动不存在");
        }

        return ResponseObject.success(activity);
    }

}

